package com.wd.jetpack.demo.paging.vm;

import androidx.lifecycle.LiveData;
import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;

import com.wd.jetpack.demo.paging.model.Movie;
import com.wd.jetpack.demo.paging.model.MovieDataSource;
import com.wd.jetpack.demo.paging.model.MovieDataSourceFactory;

/**
 * NA<BR>
 *
 * @author W4255
 * @version [V0.0.1, 2021/6/30]
 * @Description: NA
 */
public class DemoPagingViewModel {
    public LiveData<PagedList<Movie>> moviePagedList;

    public DemoPagingViewModel() {
        PagedList.Config config = new PagedList.Config.Builder()
                //设置控件占位
                .setEnablePlaceholders(false)
                .setPageSize(MovieDataSource.PER_PAGE)
                //设置当距离底部还有多少数据开始加载下一页
                .setPrefetchDistance(2)
                //设置首次加载的数量
                .setInitialLoadSizeHint(MovieDataSource.PER_PAGE * 2)
                .build();
        moviePagedList = new LivePagedListBuilder<>(new MovieDataSourceFactory(), config).build();
    }
}
